<?php
if($strStyleSheet == TRUE){
	echo "<table class='Normal' border='0' align='left' width='100%'>";
}	
if ($intOrderHeaderID){ 
    include (MODULE . "/action/qrySelectOrderHeader");
	$intOrderCarriage = $myrow["Freight"];
	$intOrderStatus = $myrow[OrderStatus];
	$intCustomerID = $myrow[Customer];
     
	echo "
	
	<tr>
	 	<td colspan = '6'>
			<hr>
		</td>
	</tr>
	
	<tr align='left' class='Normal'>
         <td align='left' colspan='6' valign='middle'>
             <H2>Order ".$myrow[ID]."</H2>
         </td>
     </tr>
    <tr class='Normal'>
         <td align='left' width='100'>"; 
		 
		 switch	($myrow[OrderStatus]){
		 	case 5:	
			case 38:
			 	echo "&nbsp;";
				break;
			default:
			   echo "
	             <a href='" . ScreenURL("EnterOrderHeader",array('intOrderHeaderID'=>$myrow[0]) ) . "'>
	             <img src='./images".SITE_SUFFIX."/update.gif' border='0' alt='Update' align='middle'></a>
				";
		 
		 
		 }
			 if( ($myrow[OrderStatus] != '5')  ){		   //||  ($myrow[OrderStatus] != '38')
			 	
			}else{
				echo "&nbsp;";
			}
echo "
		 </td>
		 <td colspan='4' align='center'>";
		echo $myrow[OrderStatus];
		 switch($myrow[OrderStatus]){
		 	case 1:
				echo "&nbsp;";
				break;
				
			case 6: case 29: case 43:   case 54: case 57: // Order status Refund 
			
				echo "
				<a href='" . ScreenURL("Refund",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Refund</a>&nbsp;";
		 		break;
		 		
			case 55:
				echo "
				<a href='" . ScreenURL("ReturnEmail.php",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Refund Email</a>";
				break;
				
			case 7:
			//case 29:
			//case 43: // Order statusReturn
				if(PURCHASE_ORDER == "DISPLAY"){
					echo "
						<a href='" . ScreenURL("ReturnNotification",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Return Notification</a>
						<a href='" . ScreenURL("ReturnEmail.php",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Refund Email</a>";
				}
				break;
				
			default:
				echo "
				 	<a href='" . ScreenURL("Invoice",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Invoice</a>&nbsp;|
					<a href='" . ScreenURL("Pro-formaInvoice",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Pro-forma</a>&nbsp;|
				 	<a href='" . ScreenURL("Receipt",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Receipt</a>&nbsp;|
					<a href='" . ScreenURL("DeliveryNote",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Delivery Note</a>&nbsp;|
					<a href='" . ScreenURL("PickingList",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Picking List</a>&nbsp;|
					<a href='" . ScreenURL("Voucher",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Voucher</a>&nbsp;|";
					if(PURCHASE_ORDER == "DISPLAY"){
						echo "
							<a href='" . ScreenURL("ReceiptEstimatedDispatch",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Receipt Estimated Dispatch </a>&nbsp;|
							<a href='" . ScreenURL("PurchaseOrder",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Purchase Order</a>&nbsp;|
							<a href='" . ScreenURL("PurchaseOrderZeon",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Zeon Purchase Order</a>&nbsp;|
							<a href='" . ScreenURL("ProductControlZeon",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Zeon Product Control</a>&nbsp;|
							<a href='" . ScreenURL("DeliveryNoteZeon",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Zeon Delivery Note</a>&nbsp;|	
							<a href='" . ScreenURL("DeliveryNoteZeon_3_line",array('intOrderHeaderID'=>$myrow[0]) ) . "' target='_blank'>Zeon 3 line Delivery Note</a>&nbsp;|
						";
					}
			
		 }
echo "
		</td>
         <td align='right' width='100'>";
			 if($myrow[OrderStatus] != '5'){
			 	echo "
	              <a href=\"" . ScreenURL("EnterOrderHeader",array('intOrderHeaderID'=>$myrow[0],'ACTION'=>"qryDeleteOrder") ) . "\"
	                 onclick=\"return confirmLink(this, 'Delete Order ".$myrow[0]."');\">
	              <img src='./images".SITE_SUFFIX."/delete.gif' border='0' alt='Delete Order ".$myrow[0]."' align='middle'></a>
	         	";
			}else{
				echo "&nbsp;";
			}
echo "
		 </td>
    </tr>

	 
	 <tr class='Normal'>
         <td align='center'>
             <b>Status</b>
         </td>
		 <td  align='center'>
		 	<b>Date Ordered</b>
		 </td>
		 <td align='center'>
             <b>Despatch Date </b>
         </td>
		 <td  align='center'>
		 	<b>Invoice</b>
		 </td>
		 <td align='center'>
             <b>Paid</b>
         </td>
		 <td  align='center'>
		 	<b>Carriage</b>
		 </td>
	</tr>
	
	<tr class='Normal'>
         <td align='left'>
             ".DisplayLookupValue("tblOrderStatus","OrderStatus",$myrow[OrderStatus])."
         </td>
		 <td  align='center'>
		 	".ReformatFromMySqlDate($myrow[OrderDate])."
		 </td>
		 <td align='center'>
             ";
			if (($myrow[ShippedDate] == '0000-00-00') && ($myrow[OrderStatus] != '1')){
				echo "<b>Awaiting Shipment</b>";
			}else{
				echo "<b>".ReformatFromMySqlDate($myrow[ShippedDate])."</b>";
			}
echo "
         </td>
		 <td  align='center'>
		 	".ReformatFromMySqlDate($myrow[InvoiceDate])."
		 </td>
		 <td align='center'>
             ".ReformatFromMySqlDate($myrow[PaidDate])."
         </td>
		 <td  align='right'>
		 	<h3>".$myrow[Freight]."</h3>
		 </td>
	</tr>";
	
		if($myrow[Courier]){
			echo "
			<tr class='Normal'>
			 	<td colspan = '6'>
					<a href=\"JavaScript: newWindow = openWin( '" . ScreenURL("DisplayCourier",array('intCourierID'=>$myrow[Courier])) . "', 'DisplayCourier', 'width=800,height=600,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1' ); newWindow.focus()\">
		             ".DisplayLookupValue("tblCourier","Courier",$myrow[Courier])."
		            </a>
				</td>
			</tr>";
		}

		if($myrow[SalesChannel] != 1){
		echo "
		<tr class='Normal'>
			<td align='left'>
				<b>Sales Channel</b>
			</td>
			<td colspan='5' align='left'>
				".DisplayLookupValue("tblSalesChannel","SalesChannel",$myrow[SalesChannel])."<br/>
			</td>
		</tr>";
		}
		
		if(EXTRA_ORDER_FIELD){
			echo "
			<tr class='Normal'>
				<td align='left'>
		             <b>".EXTRA_ORDER_FIELD."</b>
		        </td>
				<td colspan='5' align='left'>
						".$myrow["OtherInfo"]."<br/>
				</td>
			</tr>
			";
		}

echo "
	<tr class='Normal'>
		<td colspan='3' valign='top'  height='170'>
			<br/><b>Invoice to:</b>
			<br/><a href='".ScreenURL("DisplayCustomer",array('intCustomerID'=>$myrow[Customer]) )."' target='_blank'>".$myrow["ShipName"]."</a>
			<br/>".$myrow["ShipAddress"];

				if ($myrow["ShipAddress2"]){
					echo "<br/>".$myrow["ShipAddress2"];
				}
		
echo "
			<br/>".$myrow["ShipCity"]."
			<br/>".$myrow["ShipRegion"]."
			<br/>".$myrow["ShipPostalCode"]."
		</td>

		<td colspan='3' valign='top'>
			<br/><b>Deliver to:</b>
			<br/><a href='".ScreenURL("DisplayCustomer",array('intCustomerID'=>$myrow[Customer]) )."' target='_blank'>".$myrow["DeliveryName"]."</a>
			<br/>".$myrow["DeliveryAddress"];

				if ($myrow["DeliveryAddress2"]){
					echo "<br/>".$myrow["DeliveryAddress2"];
				}
		
echo "
			<br/>".$myrow["DeliveryCity"]."
			<br/>".$myrow["DeliveryRegion"]."
			<br/>".$myrow["DeliveryPostalCode"]."
		</td>
	</tr>
	
	<tr class='Normal'>
	 	<td colspan = '6'>
			<hr>
		</td>
	</tr>
";

    //ELSE
    //Nothing
	/*
	echo "
    <tr>
         <td align='left'>
             <a href='" . ScreenURL("EnterOrderHeader",array('intOrderHeaderID'=>$myrow[0]) ) . "'>
             <img src='./images".SITE_SUFFIX."/update.gif'border='0' alt='Update' align='middle'></a>
         </td>
         <td align='right'>
             <a href=\"" . ScreenURL("EnterOrderHeader",array('intOrderHeaderID'=>$myrow[0],'ACTION'=>"qryDeleteOrder") ) . "\"
                 onclick=\"return confirmLink(this, 'Delete Order ".$myrow[0]."');\">
              <img src='./images".SITE_SUFFIX."/delete.gif' border='0' alt='Delete Order ".$myrow[0]."' align='middle'></a>
        </td>
    </tr>";
	*/
echo "
	<tr class='Normal'>
		<td colspan='6'>
			<table class='Normal' width='100%' border='0'>";
			
				include (MODULE . "/screen/DisplayOrderDetails");
				
echo "
			</table>
		</td>
	</tr>";

}else{
echo "
    <tr class='Normal'>
         <td align='center'>
              No Order selected.
         </td>
    </tr>
";
}

if($strStyleSheet == TRUE){
   	echo "</table>";
}

